Method: Browser::DOM::Node#<<

Defined in:
opal/browser/dom/node.rb

#<<(node) ⇒ self

Append a child to the node.

When passing a String a text node will be created.

When passing an Object that responds to #each, every yielded element will be added following the same logic.

Parameters:

  • node (String, Node, #each, #to_n)

    the node to append

Returns:

  • (self)

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'opal/browser/dom/node.rb', line 75

def <<(node)
  if Opal.respond_to? node, :each
    node.each { |n| self << n }
    return self
  elsif Opal.respond_to? node, :to_dom
    node = node.to_dom(document)
  end

  unless native?(node)
    if String === node
      node = `#@native.ownerDocument.createTextNode(node)`
    else
      node = Native.convert(node)
    end
  end

  `#@native.appendChild(node)`

  self
end